var t = getApp();

Page({
    data: {
        language: "",
        recGoodList: [],
        hotGoodList: [],
        newGoodList: [],
        imgUrls: [],
        showCarousel: !1,
        activeIndex: 0,
        listMarginLeft: 0,
        page: 1,
        loading: !0,
        Height: 0,
        LastHeight: 0,
        share_name: "",
        share_desc: "",
        share_cover: ""
    },
    onLoad: function(t) {
        this._getSlide(), this._getData("is_recommand"), this._getData("is_hot"), this._getData(""), 
        this.getCarouselInfo();
    },
    tapNav: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.link;
        try {
            wx.navigateTo({
                url: a
            });
        } catch (t) {
            console.log(t);
        }
    },
    gotoSearch: function(t) {
        console.log(t.currentTarget.dataset.type);
        var a = t.currentTarget.dataset.type;
        wx.navigateTo({
            url: "/packageA/member/course/CourseSearch/CourseSearch?goods_type=" + a
        });
    },
    recommend_startBtn: function(t) {
        this.setData({
            startX: t.changedTouches[0].pageX
        });
    },
    recommend_moveBtn: function(t) {
        this.setData({
            endX: t.changedTouches[0].pageX
        });
    },
    recommend_endBtn: function(t) {
        var a = this.data.endX - this.data.startX;
        this.data.activeIndex >= 0 && a > 0 ? (this.data.listMarginLeft = this.data.listMarginLeft - 480, 
        this.data.activeIndex = this.data.activeIndex - 1, this.setData({
            listMarginLeft: this.data.listMarginLeft,
            activeIndex: this.data.activeIndex
        }), (this.data.listMarginLeft <= 0 || this.data.activeIndex <= 0) && this.setData({
            listMarginLeft: 0,
            activeIndex: 0
        })) : this.data.activeIndex < this.data.recGoodList.length - 1 && a < 0 && this.setData({
            listMarginLeft: this.data.listMarginLeft + 480,
            activeIndex: this.data.activeIndex + 1
        }), console.log(a, this.data.activeIndex, this.data.activeIndex, this.data.listMarginLeft);
    },
    getCarouselInfo: function() {
        var a = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.video-demand.api.video-demand.get-video-info"),
            success: function(e) {
                if (1 == e.data.result) {
                    t._isTextEmpty(e.data.data.slide) || a.setData({
                        showCarousel: !0,
                        carouselInfo: e.data.data.slide
                    }), t._isTextEmpty(e.data.data.navigation) || a.setData({
                        showCarousel: !0,
                        navigation: e.data.data.navigation
                    });
                    var s = e.data.data.share;
                    t._isTextEmpty(s) || a.setData({
                        share_name: s.share_name,
                        share_desc: s.share_desc,
                        share_cover: s.share_cover
                    }), console.log(e.data.data.slide);
                } else console.error(e);
            },
            fail: function(t) {
                console.error(t);
            }
        });
    },
    _getSlide: function(a) {
        var e = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.video-demand.api.video-demand.get-video-slide"),
            success: function(s) {
                if (1 != s.data.result || t._isTextEmpty(s.data.data)) console.error(s); else {
                    var o = s.data.data;
                    e.setData({
                        imgUrls: o
                    }), a && a(s);
                }
            },
            fail: function(t) {
                console.error(t);
            }
        });
    },
    _getData: function(a) {
        var e = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.video-demand.api.video-course-goods.get-course-goods&in_home_page=1"),
            data: {
                goods_type: a
            },
            success: function(s) {
                if (1 != s.data.result || t._isTextEmpty(s.data.data)) console.error(s); else {
                    var o = s.data.data;
                    switch (a) {
                      case "is_recommand":
                        e.setData({
                            recGoodList: o.data
                        });
                        break;

                      case "is_hot":
                        e.setData({
                            hotGoodList: o.data
                        });
                        break;

                      case "":
                        e.setData({
                            newGoodList: o.data,
                            current_page: o.current_page,
                            last_page: o.last_page
                        });
                    }
                }
            },
            fail: function(t) {
                console.error(t);
            }
        });
    },
    toCourse: function(t) {
        console.log(t.currentTarget.dataset.id);
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    moreCourse: function(t) {
        var a = t.currentTarget.dataset.type;
        if ("all" == a) wx.navigateTo({
            url: "/packageA/member/course/CourseSearch/CourseSearch?goods_type=" + a
        }); else {
            if (this.data.current_page >= this.data.last_page) return wx.showToast({
                title: "暂无更多",
                icon: "none",
                duration: 1e3
            }), void this.setData({
                loading: !1
            });
            var e = this.data.page + 1;
            this.setData({
                page: e
            }), console.log(e), this.getMore(e);
        }
    },
    _getGood: function(a) {
        t._getNetWork({
            url: t.getNetAddresss("plugin.video-demand.api.video-course-goods.get-course-goods-detail"),
            data: {
                goods_id: a
            },
            success: function(a) {
                1 != a.data.result || t._isTextEmpty(a.data.data) ? console.error(a) : wx.navigateTo({
                    url: "/packageA/detail_v2/detail_v2?id=" + itemid
                });
            },
            fail: function(t) {
                console.error(t);
            }
        });
    },
    getMore: function(a) {
        var e = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.video-demand.api.video-course-goods.get-course-goods&in_home_page=1"),
            data: {
                goods_type: "",
                page: a,
                search: ""
            },
            success: function(a) {
                if (1 != a.data.result || t._isTextEmpty(a.data.data)) console.error(a); else {
                    var s = a.data.data;
                    e.setData({
                        newGoodList: e.data.newGoodList.concat(s.data),
                        current_page: s.current_page,
                        last_page: s.last_page
                    });
                }
            },
            fail: function(t) {
                console.error(t);
            }
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        }), wx.setNavigationBarTitle({
            title: "课程"
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    imgHeight: function(t) {
        var a = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        parseInt(a) > this.data.LastHeight && (this.setData({
            Height: a
        }), this.data.LastHeight = parseInt(a));
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share_name,
            desc: this.data.share_desc,
            imageUrl: this.data.share_cover
        };
    }
});